//Shirasu Azusa 2024.6
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=2e6+5;
int T,n,sa[N],p[N],rk[N],vst[N],id[N],f[N];
char s[N],t[N];
vi e[N]; bitset<30> g[N];

int find(int x) {
  return x==id[x]?x:id[x]=find(id[x]);
}
void merge(int x,int y) {
  if(x%2==0) return;
  id[find((x+1)/2)]=find((y+1)/2);
}
void connect(int x,int y) {
  if(x%2==0) return; x=(x+1)/2, y=(y+1)/2;
  e[x].eb(y), e[y].eb(x);
}
bool manacher1() {
  int R=0,C=0;
  rep(i,0,2*n+1) f[i]=p[i];
  rep(i,1,2*n-1) f[i]++;
  int ccc=0;
  rep(i,1,2*n-1) if(i-f[i]+1<0||i+f[i]-1>2*n) return 0;
  rep(i,1,2*n-1) {
    int cur=0;
    if(R>=i) cur=min(R-i+1,f[2*C-i]);
    rep(j,cur+1,f[i]) merge(i-j+1,i+j-1), ++ccc;
    if(ccc>10000000) return 0;
    if(i+f[i]-1>R) R=i+f[i]-1, C=i;
  }
  rep(i,1,2*n-1) {
    int l=i-f[i], r=i+f[i];
    if(l>=1&&r<=2*n) connect(l,r);
  }
  return 1;
}
void manacher2() {
  int R=0,C=0;
  rep(i,0,2*n+1) f[i]=0;
  rep(i,1,n) t[2*i-1]=s[i];
  rep(i,0,n) t[2*i]='*';
  rep(i,1,2*n-1) {
    if(R>=i) f[i]=min(R-i+1,f[2*C-i]);
    while(i-f[i]>=0&&i+f[i]<=2*n&&t[i-f[i]]==t[i+f[i]]) f[i]++;
    if(i+f[i]-1>R) R=i+f[i]-1, C=i;
  }
}

void work() {
  n=read();
  rep(i,0,n+1) sa[i]=0;
  rep(i,0,2*n+1) p[i]=0;
  rep(i,1,2*n) id[i]=i, vst[i]=0, e[i].clear(), g[i].reset();
  rep(i,1,n) sa[i]=read()+1;
  rep(i,1,2*n-1) p[i]=read();
  rep(i,1,n) rk[sa[i]]=i;
  if(!manacher1()) {puts("-1"); return;}
  s[sa[1]]='a'; bool flag=1; g[find(sa[1])][0]=1;
  rep(i,2,n) {
    int x=sa[i-1], y=sa[i];
    if(rk[x+1]>rk[y+1]) {
      s[y]=s[x]+1;
    } else {
      if(vst[find(y)]) s[y]=s[x];
      else {
        bool rr=1;
        for(int v:e[find(y)]) {
          if(g[v][s[x]-'a']) rr=0;
        }
        if(rr) s[y]=s[x];
        else s[y]=s[x]+1;
      }
    }
    if(s[y]>'z') {flag=0; break;}
    g[find(y)][s[y]-'a']=1;
  }
  manacher2();
  rep(i,1,2*n-1) flag&=(p[i]==f[i]-1);
  if(!flag) puts("-1");
  else {
    rep(i,1,n) putchar(s[i]);
    puts("");
  }
}

signed main() {
  freopen("string.in","r",stdin);
  freopen("string.out","w",stdout);
  int T=read(); while(T--) work();
  return 0;
}